<?php

namespace App\Listeners;

use App\Events\FinancialFlow;
use App\Models\User;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Queue\InteractsWithQueue;

class UserBalance
{
    /**
     * Create the event listener.
     *
     * @return void
     */

    private $state = 0 ;
    public function __construct()
    {
    }

    /**
     * Handle the event.
     *
     * @param  FinancialFlow  $event
     * @return void
     */
    public function handle(FinancialFlow $event)
    {
        $user = User::find($event->model->uid);
        if ( $event->model->id) {
            $user->balance = $event->model->balance;
            $user->save();
        }else{
            $event->model->balance = $user->balance + $event->model->price;
        }

    }
}
